home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS14.ADF / Progs / CRLF.c < prev    next >
C/C++ Source or Header  |  1989-01-28  |  3KB  |  112 lines

  1. /****************************************************************
  2. **                                                             **
  3. **  Program Name  - CRLF                                       **
  4. **                                                             **
  5. **  Function      - Add or Remove CR's from a text file        **
  6. **                                                             **
  7. **  Input file    - Specified on command line                  **
  8. **                                                             **
  9. **  Output fils   - Specified on command line                  **
  10. **                                                             **
  11. **  Commands      - A = Add CR's    R = Remove CR's            **
  12. **                  Entered on Command Line                    **
  13. **                                                             **
  14. **  Written by    - John Frickson                              **
  15. **                                                             **
  16. **  Date Written  - 31-Aug-86                                  **
  17. **                                                             **
  18. **  Known Bugs    - None                                       **
  19. **                                                             **
  20. **  Maintenance   - None                                       **
  21. **                                                             **
  22. ****************************************************************/
  23.  
  24. #include "stdio.h"
  25.  
  26. FILE *input_file, *fopen ();
  27. FILE *output_file, *fopen ();
  28.  
  29. main (argc, argv)
  30.       int   argc;
  31.       char  *argv[];
  32.    {
  33.       if (argc != 4)
  34.       {
  35.          printf ("Usage - CRLF inputfile outputfile A|R\n");
  36.          printf ("        A = Add CR's  R = Remove CR's\n");
  37.          exit (0);
  38.       }
  39.       if (chkcmd (argv[3]) != NULL)
  40.          {
  41.          opnfil (argv[1], argv[2]);
  42.          fixfil (argv[3]);
  43.          clsfil ();
  44.          }
  45.  
  46.       exit (0);
  47.    }
  48.  
  49. chkcmd (cmd)
  50.    char  cmd[];
  51.    {
  52.       int   result = 0;
  53.  
  54.       if (cmd[0] == 'A' || cmd[0] == 'a' || cmd[0] == 'R' || cmd[0] == 'r')
  55.           result = 1;
  56.       else
  57.       {
  58.           printf ("Usage - CRLF inputfile outputfile A|R\n");
  59.           printf ("        A = Add CR's  R = Remove CR's\n");
  60.       }
  61.       return (result);
  62.    }          
  63.  
  64. opnfil (infile, outfile)
  65.    char  infile[], outfile[];
  66.    {
  67.       input_file = fopen (infile, "r");
  68.       if (input_file == NULL)
  69.          printf ("Input File - %s cannot be opened\n", infile);
  70.  
  71.       if (input_file != NULL)
  72.       {
  73.          output_file = fopen (outfile, "w");
  74.          if (output_file == NULL)
  75.             printf ("Output File - %s cannot be opened\n", outfile);
  76.       }
  77.    }
  78.  
  79. clsfil ()
  80.    {
  81.       if (input_file != NULL)
  82.          fclose (input_file);
  83.  
  84.       if (output_file != NULL)
  85.          fclose (output_file);
  86.    }
  87.  
  88. fixfil (cmd)
  89.    char cmd[];
  90.    {
  91.       char  c;
  92.  
  93.       if (input_file != NULL && output_file != NULL)
  94.       {
  95.          while ( ! feof (input_file))
  96.          {
  97.             c = getc (input_file);
  98.             if ( ! feof (input_file))
  99.             {
  100.                if (cmd[0] == 'A' || cmd[0] == 'a')
  101.                   {
  102.                   putc (c, output_file);
  103.                   if (c == '\n')
  104.                      putc ('\r', output_file);
  105.                   }
  106.                else if (c != '\r')
  107.                   putc (c, output_file);
  108.             }
  109.          }
  110.       }
  111.    }
  112.